package com.hongxin.nw.netty.model.analysis.info;

import com.hongxin.nw.netty.utils.FieldAnalysis;
import com.hongxin.nw.netty.values.TypeIdentif;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.9下发计费模型结果数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:15
 * @Version 1.0
 * @Descibe
 */
@Slf4j
@Getter
@Setter
public class Mrena1_5 {

    private String co; //	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String charge_inter_identify; //		充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String billing_model_id; //		计费模型ID	BIN码	8Byte	运营管理系统产生
    private String success_identify; //		成功标识	BIN码	1Btye	0：成功；1：失败

    private int idx = 0;
    private ByteBuf byteBuf;

    private Mrena1_5 subCo() {
//        this.co = substring(TypeIdentif.BYTE_CO.getbyteLength());
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CO.getInt();
//        this.co = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        this.idx += byteLength;

        this.co = FieldAnalysis.subCo(TypeIdentif.BYTE_CO.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CO.getInt();
        return this;
    }

    private Mrena1_5 subCharge_inte_identify() {
//        this.charge_inter_identify = substring(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getbyteLength());
//        this.charge_inter_identify = FieldAnalysis.analysisBin(this.charge_inter_identify);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
//        this.charge_inter_identify = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.charge_inter_identify = FieldAnalysis.analysisBin(this.charge_inter_identify);
//        this.idx += byteLength;


        this.charge_inter_identify = FieldAnalysis.subGun(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
        return this;
    }

    private Mrena1_5 subBilling_model_id() {
//        this.billing_model_id = substring(TypeIdentif.BYTE_BILLING_MODEL_ID.getbyteLength());
//        this.billing_model_id = FieldAnalysis.analysisBCD(this.billing_model_id);
//        return this;

//        int byteLength = TypeIdentif.BYTE_BILLING_MODEL_ID.getInt();
//        this.billing_model_id = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.billing_model_id = FieldAnalysis.analysisBCD(this.billing_model_id);
//        this.idx += byteLength;

        this.billing_model_id = FieldAnalysis.subBill(TypeIdentif.BYTE_BILLING_MODEL_ID.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_BILLING_MODEL_ID.getInt();
        return this;
    }

    private Mrena1_5 subSucces_identify() {
//        this.success_identify =  substring(TypeIdentif.BYTE_SUCCESS_IDENTIFY.getbyteLength());
//        this.success_identify = FieldAnalysis.analysisBin(this.success_identify);
//        return this;

//        int byteLength = TypeIdentif.BYTE_SUCCESS_IDENTIFY.getInt();
//        this.success_identify = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.success_identify = FieldAnalysis.analysisBin(this.success_identify);
//        this.idx += byteLength;


        this.success_identify = FieldAnalysis.subSuccess(TypeIdentif.BYTE_SUCCESS_IDENTIFY.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_SUCCESS_IDENTIFY.getInt();
        return this;
    }

    public Mrena1_5 analysisStr(int idx, ByteBuf byteBuf) {
        this.idx = idx;
        this.byteBuf = byteBuf;

        return this.subCo().subCharge_inte_identify().subBilling_model_id().subSucces_identify();
    }

    @Override
    public String toString() {
        return "Mrena1_5{" +
                "co='" + co + '\'' +
                ", charge_inter_identify='" + charge_inter_identify + '\'' +
                ", billing_model_id='" + billing_model_id + '\'' +
                ", success_identify='" + success_identify + '\'' +
                '}';
    }

}
